/**
 * COPYRIGHT© KMTC 2007
 * This software is the proprietary information of Korea Marine Transport Co.LTD
 * 
 * Revision History
 * Author			Date		Description
 * ------			----		-----------
 * mangnae@wees.co.kr		2008.02.14   menuControll
 */
package kr.or.javacafe.common.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.web.bind.RequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
 

public class MenuController extends MultiActionController {
	protected final Log logger = LogFactory.getLog(getClass());

	private MessageSourceAccessor messageSourceAccessor_da;
	
	public MessageSourceAccessor getMessageSourceAccessor_da() {
		return messageSourceAccessor_da;
	}

	public void setMessageSourceAccessor_da(MessageSourceAccessor messageSourceAccessor_da) {
		this.messageSourceAccessor_da = messageSourceAccessor_da;
	} 

	public ModelAndView menu(HttpServletRequest request,
			HttpServletResponse response) throws Exception{

		String referer = request.getRequestURI();


		String[] URL = referer.split("/");
		int cnt = URL.length;
		String URL1 = "";
		String URL2 = "";
		String URL3 = "";
		String URL4 = "";

		if(cnt == 3){
		URL1 = URL[cnt-2];

		URL1 = URL1.substring(0, 4);
		URL2 = URL[cnt-2].substring(0,7);
		URL3 = URL[cnt-1];
		
		try{
			URL4 = URL[cnt-2].substring(0,12);
		}catch(Exception e){
			URL4 = "";
		}
		
		logger.debug("URL:"+referer);
		logger.debug("URL1:"+URL1);
		logger.debug("URL2:"+URL2);
		logger.debug("URL3:"+URL3);
		logger.debug("URL4:"+URL4);
		 
		}else{
		URL1 = "";
		}
		ModelAndView successPage = null;
 
		
		if (URL1.equals("VOSD")||URL1.equals("CSBK")||URL1.equals("CSBL")||URL1.equals("ARAI")||URL1.equals("CCIT")) {
			successPage = new ModelAndView("/inc/leftMenu_eservice");
			successPage.addObject("menuName", URL2);
		}else if(URL4.equals("CMBA100Admin")) {
			successPage = new ModelAndView("/inc/leftMenu_board");
		}else if(URL2.equals("CMBA100")||URL2.equals("CMBA200")||URL2.equals("CMBA300")) {
			successPage = new ModelAndView("/inc/leftMenu_eservice");
			successPage.addObject("menuName", URL2);
		}else if (URL2.equals("KMTC410")||URL2.equals("KMTC411")||URL2.equals("KMTC412")) {
			successPage = new ModelAndView("/inc/leftMenu_board");
		}else {
		
			String io_flag = RequestUtils.getStringParameter(request, "flag", "O");
		
			successPage = new ModelAndView("/inc/leftMenu");
			successPage.addObject("URL1", URL1);
			successPage.addObject("URL2", URL2);
			successPage.addObject("URL3", URL3);
			successPage.addObject("io_flag", io_flag);
		}
		
		return successPage;
	}

	public ModelAndView topMenu(HttpServletRequest request,
			HttpServletResponse response) throws Exception{

		return new ModelAndView("/inc/topMenu");
	}

	

	public ModelAndView topMenu_sub(HttpServletRequest request,
			HttpServletResponse response) throws Exception{

		String referer = request.getRequestURI();



		String[] URL = referer.split("/");
		int cnt = URL.length;
		String URL1 = "";
		String URL2 = "";
		String URL3 = "";

		if(cnt == 3){
		URL1 = URL[cnt-2];

		URL1 = URL1.substring(0, 4);
		URL2 = URL[cnt-2].substring(0,7);
		URL3 = URL[cnt-1];
		logger.debug("URL:"+referer);
		logger.debug("URL2:"+URL2);
		//logger.debug("URL3:"+URL3);
	 
		}else{
		URL1 = "";
		}
		ModelAndView successPage = null;
		
		
		successPage.addObject("MENU", URL1);
		successPage.addObject("TYPE", URL2);
		successPage.addObject("FILE", URL3);

		return successPage;
	}

	public ModelAndView mainloginMenu(HttpServletRequest request,
			HttpServletResponse response) throws Exception{

		return new ModelAndView("/inc/Main_login");
	}
	
	public ModelAndView mainMenu_Top(HttpServletRequest request,
			HttpServletResponse response) throws Exception{

		return new ModelAndView("/inc/Main_Top");
	}
	

}

